<?php

namespace Business\Comment;

/**
 * 增加评论
 */
class AddModel extends \Business\AbstractModel {

    /**
     * 增加评论
     * 
     * @param array $params
     * @return
     */
    public function add($params) {
        $params = $this->_checkParams($params);

        $commentDAO = \DAO\Comment\CommentModel::getInstance();
        $result     = $commentDAO->insert($params, true);

        return $result;
    }

    /**
     * 对传入的参数进行校验
     * 
     * @param array $params
     * @return array
     * @throws \Exception
     */
    protected function _checkParams($params) {
        $form = new \Forms\Comment\AddModel($params);
        if (!$form->validate()) {
            \Error\ErrorModel::throwException(110010, current($form->getMessages()));
        }
        $params = $form->getFieldValue();
        return $params;
    }

    /**
     * 登录业务
     * 
     * @var \Business\Comment\AddModel
     */
    private static $_instance = null;

    /**
     * 单例模式获取类实例
     * 
     * @return \Business\Comment\AddModel
     */
    public static function getInstance() {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

}
